package com.sinaapp.gavinzhang.GSpider.examples;

import com.sinaapp.gavinzhang.GSpider.DefaultPageProcessor;
import com.sinaapp.gavinzhang.GSpider.Exception.GSpiderInitException;
import com.sinaapp.gavinzhang.GSpider.GSpider;
import com.sinaapp.gavinzhang.GSpider.GSpiderBuilder;
import org.jsoup.nodes.Document;

import java.util.regex.Pattern;

/**
 * Created by gavin on 15-7-23.
 */
public class Zhihu extends DefaultPageProcessor {

    @Override
    public void dispose(Document html, String webUrl) {
        //super.dispose(html, webUrl);
        System.out.println(html.title());
    }

    public static void main(String[] args) throws GSpiderInitException {
        GSpiderBuilder gSpiderBuilder = new GSpiderBuilder();
        gSpiderBuilder.addWebUrl("http://www.zhihu.com/explore");
        gSpiderBuilder.setPageProcessor(new Zhihu());
        gSpiderBuilder.addRegex(Pattern.compile("http://www.zhihu.com/question/[0-9]+"));
        GSpider gSpider = gSpiderBuilder.build();
        gSpider.controlInit();
    }

    /*public static void main(String[] args)throws Exception
    {
        GSpider nst = new GSpider();
        Pattern p = Pattern.compile("http://www.zhihu.com/question/[0-9]+");
        nst.addRegex(p);
        nst.addWebUrl("http://www.zhihu.com/explore");
        nst.controlInit();
    }*/
}
